﻿using System;
using System.Threading;

//声明一个委托类型
public delegate void AlarmHandler(object sender, AlarmEventArgs args);

public class AlarmEventArgs
{
    public string clock { get; set; }
};

public class AlarmClock
{
    // 定义事件，相当于创建委托实例
    public event AlarmHandler Tick;
    public event AlarmHandler Alarm;

    
    public void Start()
    {
        AlarmEventArgs args = new AlarmEventArgs()
        {
            clock = "闹钟开始走"
        };

        //时钟运行60s
        for (int i = 0; i < 60; i++)
        {
            // 触发 Tick 事件
            Tick(this, args);
            Thread.Sleep(1000); 

            // 触发 Alarm 事件
            if (i % 5==0)//每十秒闹钟响一次
            {
                Alarm(this, args);
            }
        }
    }
}
class Program
{
    static void Main(string[] args)
    {
        AlarmClock alarmClock = new AlarmClock();
        alarmClock.Tick += (sender, e) => Console.WriteLine("嘀嗒...");//模拟闹钟走时效果
        alarmClock.Alarm += (sender, e) => Console.WriteLine("闹钟响了！");//模拟闹钟响铃效果
        alarmClock.Start();//启动闹钟
    }
}
